
import dayjs from "dayjs";

export default {
  data () {
    return {
        datetimePickerOptions: {
          shortcuts: [
            {
              text: '今天',
              onClick (picker) {
                const end = dayjs().set("hour", 0).set("minute", 0).set("second", 0).add(1, "day");
                const start = end.add(-1, "day");
                picker.$emit('pick', [start.toDate(), end.toDate()])
              }
            },
            {
              text: '本周',
              onClick (picker) {

                const current = dayjs();
                const end = current.day(8).hour(0).minute(0).second(0);
                const start = end.add(-8, "day");
                picker.$emit('pick', [start.toDate(), end.toDate()])
              }
            },
            {
              text: '本月',
              onClick (picker) {

                const current = dayjs();

                const end = dayjs("1970-02-01 00:00:00")
                  .set("year", current.year())
                  .set("month", current.month() + 1)
                  ;

                const start = end.add(-1, "month");
                picker.$emit('pick', [start.toDate(), end.toDate()])
              }
            },
            {
              text: '今年',
              onClick (picker) {
                const end = dayjs("1970-01-01 00:00:00")
                  .set("year", dayjs().year())
                  .add(1, "year");
                const start = end.add(-1, "year");

                picker.$emit('pick', [start.toDate(), end.toDate()])
              }
            },
            {
              text: '最近一周',
              onClick (picker) {

                const current = dayjs();
                const end = current.hour(0).minute(0).second(0).add(1, "day");
                const start = end.add(-1, "week");

                picker.$emit('pick', [start.toDate(), end.toDate()])
              }
            },
            {
              text: '最近一个月',
              onClick (picker) {
                const end = dayjs().set("hour", 0).set("minute", 0).set("second", 0).add(1, "day");
                const start = end.add(-1, "month");
                picker.$emit('pick', [start.toDate(), end.toDate()])
              }
            },
            {
              text: '最近三个月',
              onClick (picker) {
                const end = dayjs().set("hour", 0).set("minute", 0).set("second", 0).add(1, "day");
                const start = end.add(-3, "month");
                picker.$emit('pick', [start.toDate(), end.toDate()])
              }
            },
            {
              text: '最近半年',
              onClick (picker) {
                const end = dayjs().set("hour", 0).set("minute", 0).set("second", 0).add(1, "day");
                const start = end.add(-6, "month");
                picker.$emit('pick', [start.toDate(), end.toDate()])
              }
            },
            {
              text: '最近一年',
              onClick (picker) {
                const end = dayjs().set("hour", 0).set("minute", 0).set("second", 0).add(1, "day");
                const start = end.add(-1, "year");
                picker.$emit('pick', [start.toDate(), end.toDate()])
              }
            },
          ],
        },
    };
  },
};
